//
//  XDHomeworkHeaderView.m
//  XDEducation
//
//  Created by apple on 2017/4/28.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDHomeworkHeaderView.h"

@interface XDHomeworkHeaderView ()

/** button title  */
@property(nonatomic,strong) NSArray *titleArr;

/** 选择button */
@property(nonatomic,strong) UIButton *selectedBtn;

@end

@implementation XDHomeworkHeaderView



-(instancetype)init{
    
    if (self = [super init]) {
        
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}




-(void)layoutSubviews{
    
    [super layoutSubviews];
    CGFloat padding = 10;
    CGFloat buttonW = (ScreenW - 4*padding)/3;
    CGFloat buttonH = self.height;
    for (int i = 0; i < 3; i ++) {
        
        UIButton *button = [[UIButton alloc]init];
        button.frame = CGRectMake(padding + (buttonW + padding )* i , 0, buttonW, buttonH);
        [button setTitle:self.titleArr[i] forState:UIControlStateNormal];
        [button setTitleColor:UIColorFromRGB(0x4c4c4c) forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"btn_blue_selected"] forState:UIControlStateSelected];
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        button.tag = 1100+i;
        [self addSubview:button];
        [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        if(i == 0){
            
            button.selected = YES;
            _selectedBtn = button;
            
        }
        
    }
}

-(NSArray *)titleArr{
    if (!_titleArr) {
        _titleArr = [NSArray arrayWithObjects:
                     @"个性化作业",
                     @"星星银行",
                     @"辅导课作业",
                     nil];
    }
    return _titleArr;
}

-(void)buttonClicked:(UIButton *)button{

    if (button != _selectedBtn) {
        
        _selectedBtn.selected = !_selectedBtn.selected;
        
        button.selected  = !button.selected;
        
        _selectedBtn = button;
        self.ClickHeaderButton ((button.tag - 1100));
    }

}


@end
